<%-- 
    Document   : Products
    Created on : Aug 24, 2011, 7:12:45 PM
    Author     : Thanhnd
--%>


<%@page import="accessor.Category"%>
<%@page import="accessor.CategoryDAO"%>
<%@page import="accessor.ProductCategoryDAO"%>
<%@page import="accessor.ProductCategory"%>
<%@page import="accessor.Products"%>
<%@page import="java.util.List"%>
<%@page import="accessor.ProductsAccessor"%>
<%@include file="header.jsp" %>
<%
    if(request.getParameter("id")==null){
               response.sendRedirect("products.jsp");
    }
%>
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />

<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/style.css" type="text/css" media="screen" />

<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />	

<!-- Colour Schemes

Default colour scheme is green. Uncomment prefered stylesheet to use it.

<link rel="stylesheet" href="resources/css/blue.css" type="text/css" media="screen" />

<link rel="stylesheet" href="resources/css/red.css" type="text/css" media="screen" />  

-->

<!-- Internet Explorer Fixes Stylesheet -->

<!--[if lte IE 7]>
        <link rel="stylesheet" href="resources/css/ie.css" type="text/css" media="screen" />
<![endif]-->

<!--                       Javascripts                       -->

<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.3.2.min.js"></script>

<!-- jQuery Configuration -->
<script type="text/javascript" src="resources/scripts/simpla.jquery.configuration.js"></script>

<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>

<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
<% ProductsAccessor pa = new ProductsAccessor();
int id = Integer.parseInt(request.getParameter("id"));
Products product = pa.getProductById(id);
%>
<h2>Product Edit <%= product.getProductName() %> </h2>
<p id="page-intro"></p>

<div class="clear"></div>
<ul class="shortcut-buttons-set">


    <li><a class="shortcut-button new-page" href="#"><span class="png_bg">
                Category List
            </span></a></li>

    <li><a class="shortcut-button upload-image" href="#"><span class="png_bg">
                Ware House
            </span></a></li>

</li>

</ul>
<div class="clear"></div>
<div class="content-box"><!-- Start Content Box -->

    <div class="content-box-header">

        <h3 style="cursor: s-resize; ">Product</h3>

        <ul class="content-box-tabs">
           
            <li><a href="#tab2">Forms</a></li>
        </ul>

        <div class="clear"></div>

    </div> <!-- End .content-box-header -->

    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab2" style="display: none; ">
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
             <form action="../productsEdit" method="post" id="target" onsubmit="MM_validateForm('Name','','R','Quantity','','RisNum','Price','','RisNum');return document.MM_returnValue">

                <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
                  
                    <p>
                        <label>Product Name</label>
                        <input class="text-input small-input" type="text" id="Name" name="Name" value="<%= product.getProductName() %>"/>
                      
                        <br><small>* Product name is required</small>
                    </p>
                    <p>
                        <label>Category</label>
                        <select name="category" class="small-input">
                            <%
                                CategoryDAO catDao = new CategoryDAO();
                                List<Category> listCat = catDao.getAllCategory();
                                int catId = product.getDefaultCategoryID();
                                for (int i = 0; i < listCat.size(); i++) {
                                    if(listCat.get(i).getCategoryID()==catId){
                                        out.print("<option selected=\"selected\" value=\"" + listCat.get(i).getCategoryID() + "\">" + listCat.get(i).getCategoryName() + "</option>");
                                    }else{
                                        out.print("<option value=\"" + listCat.get(i).getCategoryID() + "\">" + listCat.get(i).getCategoryName() + "</option>");
                                    }
                                }
                            %>

                        </select>
                        <br><small>* Chose category</small>
                    </p>
                    <p>
                        <label>Quantity</label>
                        <input class="text-input small-input" type="text" id="Quantity" name="quantity" value="<%= product.getQuantity() %>">
                        <br><small>* Quantity of product</small>
                    </p>
                    <p>
                        <label>Price</label>
                        <input class="text-input small-input" type="text" id="Price" name="price" value="<%= product.getPrice() %>">
                        <br><small>* Price of product</small>
                    </p>
                    <p>
                        <label>Image</label>
                        <input class="text-input small-input" type="text" id="small-input2" name="image">
                        <br><small>* Image</small>
                    </p>
                    <input type="submit" class="button" onclick="validate();" value="Edit" />
                </fieldset>

                <div class="clear"></div><!-- End .clear -->
                <input type="hidden" name="pID" id="pID" value="<%= product.getProductID() %>" />
            </form>

        </div> <!-- End #tab2 -->        

    </div> <!-- End .content-box-content -->

</div>

<%@include file="footer.jsp" %>
